package com.example.ymm.modules1.service.impl.user;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.dynamic.datasource.annotation.DSTransactional;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.ymm.base.BaseServiceImpl;
import com.example.ymm.model.TableList;
import com.example.ymm.model.YmPageDto;
import com.example.ymm.modules1.entity.my.user.DbApprovalNode;
import com.example.ymm.modules1.mapper.my.user.DbApprovalNodeMapper;
import com.example.ymm.modules1.query.DbApprovalNodeQueryCriteria;
import com.example.ymm.modules1.service.user.DbApprovalNodeService;
import com.example.ymm.util.QueryHelpPlus;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@DSTransactional
@DS("slave2")
@Slf4j
public class DbApprovalNodeServiceImpl extends BaseServiceImpl<DbApprovalNodeMapper, DbApprovalNode> implements DbApprovalNodeService {

    @Override
    public TableList<DbApprovalNode> list(DbApprovalNodeQueryCriteria criteria, YmPageDto pageDto) {
        IPage<DbApprovalNode> page = new Page<DbApprovalNode>(pageDto.getPage(),pageDto.getPageSize());
        QueryWrapper predicate = QueryHelpPlus.getPredicate(DbApprovalNode.class, criteria);
        predicate.orderByAsc("sort");
        baseMapper.selectPage(page, predicate);
        TableList<DbApprovalNode> tableList=new TableList(page);
        return tableList;
    }

    public List<DbApprovalNode> queryAll(DbApprovalNodeQueryCriteria criteria) {
        QueryWrapper predicate = QueryHelpPlus.getPredicate(DbApprovalNode.class, criteria);
        predicate.orderByAsc("sort");
        List<DbApprovalNode> result =baseMapper.selectList(predicate);
        return result;
    }
}
